a=int(input())
x=0
A=a/2
L=1
v=a/3
for I in range (0,10001):
    if A==I or v==I:
        x=x+1
P=a
b=a//10
c=b/2
C=b/3
for i in range(0,1001):
    if c==i or C==i:
        x=x+1
if x>0:
    o=b
if o>P:
    O=o
else:
    O=P
k=b//10
G=k/2
g=k/3
for p in range(0,101):
    if G==p or g==p:
        x=x+1
if x>2:
    L=k
V=k//10
Z=V/2
T=V/3
for s in range(0,11):
    if T==s or Z==s:
        x=x+1
if x>3:
    L=V
if a>10000 or a<999:
    print(0)
if x==4:
    print(0)
if x==4:
    print(0)
if L>O:
    O=L
    print(O)
else:
    print(O)

        
